#include <cstring>
#include <functional>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>

#define lld long long
#define ENDL '\n'
using std::cin;
using std::cout;
using std::endl;
using std::string;

const int N = 2e5 + 3;
const lld MOD = 998244353;

lld frac[N];

void pre_frac() {
  frac[0] = 1;
  frac[1] = 1;
  for (int i = 2; i < N; ++i) {
    frac[i] = (frac[i - 1] % MOD * (i % MOD)) % MOD;
  }
}

void solve() {
  int n, x = 0, cnt = 0;
  cin >> n;
  lld a[N];

  for (int i = 0; i < n; ++i)
    cin >> a[i], x |= a[i];

  for (int i = 0; i < n; ++i)
    if (a[i] == x)
      cnt++;

  lld ans;
  if (n == 2) {
    ans = (cnt % MOD * ((cnt - 1) % MOD)) % MOD;
  } else {
    ans = (cnt % MOD * ((cnt - 1) % MOD)) % MOD;
    ans = (ans % MOD * frac[n - 2] % MOD) % MOD;
  }
  cout << ans << ENDL;
}

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);

  pre_frac();
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}